package com.brain.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;

import com.brain.util.DBSettingData;
import com.brain.vo.SettingVO;

public class SettingActivity extends Activity  implements View.OnTouchListener {
	private ImageButton ground_sound_btn,  effect_sound_btn, measure_btn, healing_game_btn;
	private int cnt = 0;
    DBSettingData   db;
    private String  kind = "";
    private String  groundSound = "";
    private String  effectSound = "";
    private String  tutorialChk = "";
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.setting);
        
        ground_sound_btn   = (ImageButton) findViewById(R.id.ground_sound_btn);
        effect_sound_btn   = (ImageButton) findViewById(R.id.effect_sound_btn);
        measure_btn		   = (ImageButton) findViewById(R.id.measure_btn);
        healing_game_btn   = (ImageButton) findViewById(R.id.healing_game_btn);
  
        ground_sound_btn.setOnTouchListener(SettingActivity.this);
        effect_sound_btn.setOnTouchListener(SettingActivity.this);
        measure_btn.setOnTouchListener(SettingActivity.this);
        healing_game_btn.setOnTouchListener(SettingActivity.this);

        db = new DBSettingData(this);
        SettingVO vo = db.getData(this);
        
        if(vo != null) {
        	if(vo.getGroundSound().equals("ON")) {
            	ground_sound_btn.setImageResource(R.drawable.btn_on);
        	} else {
        		ground_sound_btn.setImageResource(R.drawable.btn_off);
         	}
           	if(vo.getEffectSound().equals("ON")) {
            	effect_sound_btn.setImageResource(R.drawable.btn_on);
        	} else {
        		effect_sound_btn.setImageResource(R.drawable.btn_off);
         	}
        	kind = "U";
        	
        	groundSound = vo.getGroundSound();
        	effectSound = vo.getEffectSound();
        	tutorialChk = vo.getTutorialChk();
        } else {
           	kind   = "I";
           	tutorialChk  = "N";
         	groundSound  = "ON";
           	effectSound  = "ON";
        }

    }
    
    public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		 if(v == ground_sound_btn) {  
			if (event.getAction() == MotionEvent.ACTION_DOWN) {
			} else if (event.getAction() == MotionEvent.ACTION_UP) {
				if(groundSound.equals("ON")) {
					ground_sound_btn.setImageResource(R.drawable.btn_off);
					groundSound = "OFF";
				} else {
					ground_sound_btn.setImageResource(R.drawable.btn_on);
					groundSound = "ON";
				}
				try {
					db.prcsRevival(SettingActivity.this, kind, tutorialChk, groundSound, effectSound);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		} else if(v == effect_sound_btn) {  
			if (event.getAction() == MotionEvent.ACTION_DOWN) {
			} else if (event.getAction() == MotionEvent.ACTION_UP) {
				if(effectSound.equals("ON")) {
					effect_sound_btn.setImageResource(R.drawable.btn_off);
					effectSound = "OFF";
				} else {
					effect_sound_btn.setImageResource(R.drawable.btn_on);
					effectSound = "ON";
				}
				try {
					db.prcsRevival(SettingActivity.this, kind, tutorialChk, groundSound, effectSound);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}				
			}					
		} else if(v == measure_btn) {  
			if (event.getAction() == MotionEvent.ACTION_DOWN) {
			} else if (event.getAction() == MotionEvent.ACTION_UP) {
				
			}					
		} else if(v == healing_game_btn) {  
			if (event.getAction() == MotionEvent.ACTION_DOWN) {
			} else if (event.getAction() == MotionEvent.ACTION_UP) {
				
			}					
		}
		 
		return false;
	}
           
}
